package designPatterns.单例;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Calendar;

public class HungrySingletonTest {

    private static final HungrySingletonTest instance = new HungrySingletonTest();

    private HungrySingletonTest() {
    }

    public static HungrySingletonTest getInstance() {
        return instance;
    }

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        HungrySingletonTest instance = HungrySingletonTest.getInstance();
        Constructor constructor = HungrySingletonTest.class.getDeclaredConstructor();
        constructor.setAccessible(true);    // 获得权限
        HungrySingletonTest newInstance = (HungrySingletonTest) constructor.newInstance();
        System.out.println(instance);
        System.out.println(newInstance);
        System.out.println(instance == newInstance);
    }

}
